<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios 创建对象发送请求</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
</head>
<body>
    <button>王者荣耀</button>
    <button>英雄联盟</button>
<hr>
    <button>书籍</button>
    <button>电影</button>

    <script>
        //获取按钮
        let btns = document.querySelectorAll('button');

        //创建 axios 实例
        let xiaohighAxios = axios.create({
            baseURL: 'http://api.xiaohigh.com',
            timeout: 1000,
            headers: {
                token: 'asdfaeafweaf'
            }
        });

        let localAxios = axios.create({
            baseURL: "http://127.0.0.1:3000"
        });


        //第一个按钮
        btns[0].onclick = async function(){
            let response = await xiaohighAxios.get('/heros');
            console.log(response);
        }

        //第二个按钮
        btns[1].onclick = async function(){
            let response = await xiaohighAxios.get('/lol');
            console.log(response);
        }

        //第三个按钮
        btns[2].onclick = async function(){
            let response = await localAxios.get('/book');
            console.log(response);
        }

        //第四个按钮
        btns[3].onclick = async function(){
            let response = await localAxios.get('/movie');
            console.log(response);
        }
    </script>
</body>
</html>